#ifndef H_RCGD_MAIN_H
#define H_RCGD_MAIN_H

/*=================================================================*/
/*                           define                                                                        */
/*=================================================================*/
/* Start Mode */
#define COLD_START			0
#define WARM_START			1
#define DOWN_LOAD			2


#define MaxLogSize	1000


typedef struct{

	char common_port_task;
	char autoreply_task;
	char startup_task;
	char eb_task;
	char control_task;
	char temperature_task;
	char pll_task_1;
	char pll_task_2;
	char start_trace_task;
	char check_lock_task;
	char eb_event_task;
	char diag_task;
	char config_log_task;
	char counter_shift_task;
	char manual_start_task;
	char scc2_task;
	char led_task;
	char led_blink_task;
	char rb_task;
	char e1_task;
	char is_over10e6_task;
	char monitor_cnt_task;
	char fpga_tod_task;
	int parameter;

}func_;
extern func_ func;


typedef struct{
	char debug;
	char dual;
	char eb;
	char holdover;
} monitor_;

extern monitor_	monitor;

/*=================================================================*/
/*                            declaration                                                                   */
/*=================================================================*/
extern int TimeSliceCounter;


extern SYS_    SYSTEM;
extern GC_     GC;
extern EVENT_  EVENT;
extern TEMPER_ TEMPERATURE;
extern USER_   USER;
extern CL_     CHECKLOCK;
extern TOD_    TOD;
extern STATUS_ STATUS;
extern RT_	   TASK;



//#define PROMPT_LENGTH	9
#define PROMPT_LENGTH	8

extern char PROMPT[PROMPT_LENGTH+1];

extern int WarmupTimeCounter;

extern void send_version();

extern char	MESG[2049];


extern char	MANUAL_START;

extern void MonitorGPSinput();



extern unsigned char GPS_Rx_Buf[GPSRXBUFSIZE];





typedef struct{
	int temp_sel;
	
	unsigned int get_ocxo;
	unsigned int get_board;
	
	unsigned int prev_ocxo;
	unsigned int prev_board;

	int ocxo_ok_cnt;
	int board_ok_cnt;
	
	int ocxo_err_cnt;
	int board_err_cnt;
	
	char ocxo_err;
	char board_err;
	
	int ocxo_match_cnt;
	int board_match_cnt;

	float ocxo_temp;
	float board_temp;
	
	float prev_ocxo_temp;
	float prev_board_temp;
	
}TempSen_ ;
extern TempSen_ ts; 




typedef struct{
	char TraceControl;
	int step;
	int step_cnt;
	double RD_1st;
	double RD_2nd;
	
	int detailSense;
	int detail;
	int DetailOffset;
	char cnt;
	
	int trace_cnt;
	int trace_interval;
	int match_cnt;
	double ro_sum;
	double aveoffset;
	
}ocxoid_ ;
extern ocxoid_ OCXOID; 

extern char TOD_TASK;
extern char TOD_MAKE_TASK;
extern char TOD_MAKE_TASK_STEP;

extern void hw10ms_int_handler(int signum);
void Init_POSITION();
void Init_POSITION2();
void Start_Position_Survey(char mode);
void Survey_Position();

#define M_THRESHOLD_WDT_CLEAR	1000

void clear_Wdt(int signo);

#define Debug_Halt(x) //printf(">>-- %d --<<\n",x)

extern SYS_ SYSTEM;

extern void mclock_init( void );
extern long int mclock( void );
extern void Monitor10msHWInterrupt();
extern void ClearMonitor10msHWInterrupt();
extern long int prevUs;
extern int b10msIntError1st;
extern long int i10msIntErrorCnt;


#endif
